#include "Colors.h"
#include "String.h"
#include <string>
#include <unordered_map>

namespace BaseType
{
class ColorManager
{
public:
    std::unordered_map<std::wstring, uint32_t> _mapColor;
    ColorManager();
    ~ColorManager() {};
    bool GetColor(const String& strClr, uint32_t& clr) {
        std::wstring str(strClr.c_str());
        if (_mapColor.contains(str)) {
            clr = _mapColor[str];
            return true;
        }
        return false;
    };
    String ColorToString(Color clr) {
        for (auto it : _mapColor) {
            if (it.second == (uint32_t)clr) {
                return String(it.first.c_str());
            }
        }
        return Color::ToHex(clr);
    };
};

Color Colors::AliceBlue = 0xFFF0F8FF;
Color Colors::AntiqueWhite = 0xFFFAEBD7;
Color Colors::Aqua = 0xFF00FFFF;
Color Colors::Aquamarine = 0xFF7FFFD4;
Color Colors::Azure = 0xFFF0FFFF;
Color Colors::Beige = 0xFFF5F5DC;
Color Colors::Bisque = 0xFFFFE4C4;
Color Colors::Black = 0xFF000000;
Color Colors::BlanchedAlmond = 0xFFFFEBCD;
Color Colors::Blue = 0xFF0000FF;
Color Colors::BlueViolet = 0xFF8A2BE2;
Color Colors::Brown = 0xFFA52A2A;
Color Colors::BurlyWood = 0xFFDEB887;
Color Colors::CadetBlue = 0xFF5F9EA0;
Color Colors::Chartreuse = 0xFF7FFF00;
Color Colors::Chocolate = 0xFFD2691E;
Color Colors::Coral = 0xFFFF7F50;
Color Colors::CornflowerBlue = 0xFF6495ED;
Color Colors::Cornsilk = 0xFFFFF8DC;
Color Colors::Crimson = 0xFFDC143C;
Color Colors::Cyan = 0xFF00FFFF;
Color Colors::DarkBlue = 0xFF00008B;
Color Colors::DarkCyan = 0xFF008B8B;
Color Colors::DarkGoldenrod = 0xFFB8860B;
Color Colors::DarkGray = 0xFFA9A9A9;
Color Colors::DarkGreen = 0xFF006400;
Color Colors::DarkKhaki = 0xFFBDB76B;
Color Colors::DarkMagenta = 0xFF8B008B;
Color Colors::DarkOliveGreen = 0xFF556B2F;
Color Colors::DarkOrange = 0xFFFF8C00;
Color Colors::DarkOrchid = 0xFF9932CC;
Color Colors::DarkRed = 0xFF8B0000;
Color Colors::DarkSalmon = 0xFFE9967A;
Color Colors::DarkSeaGreen = 0xFF8FBC8F;
Color Colors::DarkSlateBlue = 0xFF483D8B;
Color Colors::DarkSlateGray = 0xFF2F4F4F;
Color Colors::DarkTurquoise = 0xFF00CED1;
Color Colors::DarkViolet = 0xFF9400D3;
Color Colors::DeepPink = 0xFFFF1493;
Color Colors::DeepSkyBlue = 0xFF00BFFF;
Color Colors::DimGray = 0xFF696969;
Color Colors::DodgerBlue = 0xFF1E90FF;
Color Colors::Firebrick = 0xFFB22222;
Color Colors::FloralWhite = 0xFFFFFAF0;
Color Colors::ForestGreen = 0xFF228B22;
Color Colors::Fuchsia = 0xFFFF00FF;
Color Colors::Gainsboro = 0xFFDCDCDC;
Color Colors::GhostWhite = 0xFFF8F8FF;
Color Colors::Gold = 0xFFFFD700;
Color Colors::Goldenrod = 0xFFDAA520;
Color Colors::Gray = 0xFF808080;
Color Colors::Green = 0xFF008000;
Color Colors::GreenYellow = 0xFFADFF2F;
Color Colors::Honeydew = 0xFFF0FFF0;
Color Colors::HotPink = 0xFFFF69B4;
Color Colors::IndianRed = 0xFFCD5C5C;
Color Colors::Indigo = 0xFF4B0082;
Color Colors::Ivory = 0xFFFFFFF0;
Color Colors::Khaki = 0xFFF0E68C;
Color Colors::Lavender = 0xFFE6E6FA;
Color Colors::LavenderBlush = 0xFFFFF0F5;
Color Colors::LawnGreen = 0xFF7CFC00;
Color Colors::LemonChiffon = 0xFFFFFACD;
Color Colors::LightBlue = 0xFFADD8E6;
Color Colors::LightCoral = 0xFFF08080;
Color Colors::LightCyan = 0xFFE0FFFF;
Color Colors::LightGoldenrodYellow = 0xFFFAFAD2;
Color Colors::LightGreen = 0xFF90EE90;
Color Colors::LightGray = 0xFFD3D3D3;
Color Colors::LightPink = 0xFFFFB6C1;
Color Colors::LightSalmon = 0xFFFFA07A;
Color Colors::LightSeaGreen = 0xFF20B2AA;
Color Colors::LightSkyBlue = 0xFF87CEFA;
Color Colors::LightSlateGray = 0xFF778899;
Color Colors::LightSteelBlue = 0xFFB0C4DE;
Color Colors::LightYellow = 0xFFFFFFE0;
Color Colors::Lime = 0xFF00FF00;
Color Colors::LimeGreen = 0xFF32CD32;
Color Colors::Linen = 0xFFFAF0E6;
Color Colors::Magenta = 0xFFFF00FF;
Color Colors::Maroon = 0xFF800000;
Color Colors::MediumAquamarine = 0xFF66CDAA;
Color Colors::MediumBlue = 0xFF0000CD;
Color Colors::MediumOrchid = 0xFFBA55D3;
Color Colors::MediumPurple = 0xFF9370DB;
Color Colors::MediumSeaGreen = 0xFF3CB371;
Color Colors::MediumSlateBlue = 0xFF7B68EE;
Color Colors::MediumSpringGreen = 0xFF00FA9A;
Color Colors::MediumTurquoise = 0xFF48D1CC;
Color Colors::MediumVioletRed = 0xFFC71585;
Color Colors::MidnightBlue = 0xFF191970;
Color Colors::MintCream = 0xFFF5FFFA;
Color Colors::MistyRose = 0xFFFFE4E1;
Color Colors::Moccasin = 0xFFFFE4B5;
Color Colors::NavajoWhite = 0xFFFFDEAD;
Color Colors::Navy = 0xFF000080;
Color Colors::OldLace = 0xFFFDF5E6;
Color Colors::Olive = 0xFF808000;
Color Colors::OliveDrab = 0xFF6B8E23;
Color Colors::Orange = 0xFFFFA500;
Color Colors::OrangeRed = 0xFFFF4500;
Color Colors::Orchid = 0xFFDA70D6;
Color Colors::PaleGoldenrod = 0xFFEEE8AA;
Color Colors::PaleGreen = 0xFF98FB98;
Color Colors::PaleTurquoise = 0xFFAFEEEE;
Color Colors::PaleVioletRed = 0xFFDB7093;
Color Colors::PapayaWhip = 0xFFFFEFD5;
Color Colors::PeachPuff = 0xFFFFDAB9;
Color Colors::Peru = 0xFFCD853F;
Color Colors::Pink = 0xFFFFC0CB;
Color Colors::Plum = 0xFFDDA0DD;
Color Colors::PowderBlue = 0xFFB0E0E6;
Color Colors::Purple = 0xFF800080;
Color Colors::Red = 0xFFFF0000;
Color Colors::RosyBrown = 0xFFBC8F8F;
Color Colors::RoyalBlue = 0xFF4169E1;
Color Colors::SaddleBrown = 0xFF8B4513;
Color Colors::Salmon = 0xFFFA8072;
Color Colors::SandyBrown = 0xFFF4A460;
Color Colors::SeaGreen = 0xFF2E8B57;
Color Colors::SeaShell = 0xFFFFF5EE;
Color Colors::Sienna = 0xFFA0522D;
Color Colors::Silver = 0xFFC0C0C0;
Color Colors::SkyBlue = 0xFF87CEEB;
Color Colors::SlateBlue = 0xFF6A5ACD;
Color Colors::SlateGray = 0xFF708090;
Color Colors::Snow = 0xFFFFFAFA;
Color Colors::SpringGreen = 0xFF00FF7F;
Color Colors::SteelBlue = 0xFF4682B4;
Color Colors::Tan = 0xFFD2B48C;
Color Colors::Teal = 0xFF008080;
Color Colors::Thistle = 0xFFD8BFD8;
Color Colors::Tomato = 0xFFFF6347;
Color Colors::Turquoise = 0xFF40E0D0;
Color Colors::Violet = 0xFFEE82EE;
Color Colors::Wheat = 0xFFF5DEB3;
Color Colors::White = 0xFFFFFFFF;
Color Colors::WhiteSmoke = 0xFFF5F5F5;
Color Colors::Yellow = 0xFFFFFF00;
Color Colors::YellowGreen = 0xFF9ACD32;

ColorManager::ColorManager()
{
    _mapColor.emplace(std::wstring(L"AliceBlue"), 0xFFF0F8FF);
    _mapColor.emplace(std::wstring(L"AntiqueWhite"), 0xFFFAEBD7);
    _mapColor.emplace(std::wstring(L"Aqua"), 0xFF00FFFF);
    _mapColor.emplace(std::wstring(L"Aquamarine"), 0xFF7FFFD4);
    _mapColor.emplace(std::wstring(L"Azure"), 0xFFF0FFFF);
    _mapColor.emplace(std::wstring(L"Beige"), 0xFFF5F5DC);
    _mapColor.emplace(std::wstring(L"Bisque"), 0xFFFFE4C4);
    _mapColor.emplace(std::wstring(L"Black"), 0xFF000000);
    _mapColor.emplace(std::wstring(L"BlanchedAlmond"), 0xFFFFEBCD);
    _mapColor.emplace(std::wstring(L"Blue"), 0xFF0000FF);
    _mapColor.emplace(std::wstring(L"BlueViolet"), 0xFF8A2BE2);
    _mapColor.emplace(std::wstring(L"Brown"), 0xFFA52A2A);
    _mapColor.emplace(std::wstring(L"BurlyWood"), 0xFFDEB887);
    _mapColor.emplace(std::wstring(L"CadetBlue"), 0xFF5F9EA0);
    _mapColor.emplace(std::wstring(L"Chartreuse"), 0xFF7FFF00);
    _mapColor.emplace(std::wstring(L"Chocolate"), 0xFFD2691E);
    _mapColor.emplace(std::wstring(L"Coral"), 0xFFFF7F50);
    _mapColor.emplace(std::wstring(L"CornflowerBlue"), 0xFF6495ED);
    _mapColor.emplace(std::wstring(L"Cornsilk"), 0xFFFFF8DC);
    _mapColor.emplace(std::wstring(L"Crimson"), 0xFFDC143C);
    _mapColor.emplace(std::wstring(L"Cyan"), 0xFF00FFFF);
    _mapColor.emplace(std::wstring(L"DarkBlue"), 0xFF00008B);
    _mapColor.emplace(std::wstring(L"DarkCyan"), 0xFF008B8B);
    _mapColor.emplace(std::wstring(L"DarkGoldenrod"), 0xFFB8860B);
    _mapColor.emplace(std::wstring(L"DarkGray"), 0xFFA9A9A9);
    _mapColor.emplace(std::wstring(L"DarkGreen"), 0xFF006400);
    _mapColor.emplace(std::wstring(L"DarkKhaki"), 0xFFBDB76B);
    _mapColor.emplace(std::wstring(L"DarkMagenta"), 0xFF8B008B);
    _mapColor.emplace(std::wstring(L"DarkOliveGreen"), 0xFF556B2F);
    _mapColor.emplace(std::wstring(L"DarkOrange"), 0xFFFF8C00);
    _mapColor.emplace(std::wstring(L"DarkOrchid"), 0xFF9932CC);
    _mapColor.emplace(std::wstring(L"DarkRed"), 0xFF8B0000);
    _mapColor.emplace(std::wstring(L"DarkSalmon"), 0xFFE9967A);
    _mapColor.emplace(std::wstring(L"DarkSeaGreen"), 0xFF8FBC8F);
    _mapColor.emplace(std::wstring(L"DarkSlateBlue"), 0xFF483D8B);
    _mapColor.emplace(std::wstring(L"DarkSlateGray"), 0xFF2F4F4F);
    _mapColor.emplace(std::wstring(L"DarkTurquoise"), 0xFF00CED1);
    _mapColor.emplace(std::wstring(L"DarkViolet"), 0xFF9400D3);
    _mapColor.emplace(std::wstring(L"DeepPink"), 0xFFFF1493);
    _mapColor.emplace(std::wstring(L"DeepSkyBlue"), 0xFF00BFFF);
    _mapColor.emplace(std::wstring(L"DimGray"), 0xFF696969);
    _mapColor.emplace(std::wstring(L"DodgerBlue"), 0xFF1E90FF);
    _mapColor.emplace(std::wstring(L"Firebrick"), 0xFFB22222);
    _mapColor.emplace(std::wstring(L"FloralWhite"), 0xFFFFFAF0);
    _mapColor.emplace(std::wstring(L"ForestGreen"), 0xFF228B22);
    _mapColor.emplace(std::wstring(L"Fuchsia"), 0xFFFF00FF);
    _mapColor.emplace(std::wstring(L"Gainsboro"), 0xFFDCDCDC);
    _mapColor.emplace(std::wstring(L"GhostWhite"), 0xFFF8F8FF);
    _mapColor.emplace(std::wstring(L"Gold"), 0xFFFFD700);
    _mapColor.emplace(std::wstring(L"Goldenrod"), 0xFFDAA520);
    _mapColor.emplace(std::wstring(L"Gray"), 0xFF808080);
    _mapColor.emplace(std::wstring(L"Green"), 0xFF008000);
    _mapColor.emplace(std::wstring(L"GreenYellow"), 0xFFADFF2F);
    _mapColor.emplace(std::wstring(L"Honeydew"), 0xFFF0FFF0);
    _mapColor.emplace(std::wstring(L"HotPink"), 0xFFFF69B4);
    _mapColor.emplace(std::wstring(L"IndianRed"), 0xFFCD5C5C);
    _mapColor.emplace(std::wstring(L"Indigo"), 0xFF4B0082);
    _mapColor.emplace(std::wstring(L"Ivory"), 0xFFFFFFF0);
    _mapColor.emplace(std::wstring(L"Khaki"), 0xFFF0E68C);
    _mapColor.emplace(std::wstring(L"Lavender"), 0xFFE6E6FA);
    _mapColor.emplace(std::wstring(L"LavenderBlush"), 0xFFFFF0F5);
    _mapColor.emplace(std::wstring(L"LawnGreen"), 0xFF7CFC00);
    _mapColor.emplace(std::wstring(L"LemonChiffon"), 0xFFFFFACD);
    _mapColor.emplace(std::wstring(L"LightBlue"), 0xFFADD8E6);
    _mapColor.emplace(std::wstring(L"LightCoral"), 0xFFF08080);
    _mapColor.emplace(std::wstring(L"LightCyan"), 0xFFE0FFFF);
    _mapColor.emplace(std::wstring(L"LightGoldenrodYellow"), 0xFFFAFAD2);
    _mapColor.emplace(std::wstring(L"LightGreen"), 0xFF90EE90);
    _mapColor.emplace(std::wstring(L"LightGray"), 0xFFD3D3D3);
    _mapColor.emplace(std::wstring(L"LightPink"), 0xFFFFB6C1);
    _mapColor.emplace(std::wstring(L"LightSalmon"), 0xFFFFA07A);
    _mapColor.emplace(std::wstring(L"LightSeaGreen"), 0xFF20B2AA);
    _mapColor.emplace(std::wstring(L"LightSkyBlue"), 0xFF87CEFA);
    _mapColor.emplace(std::wstring(L"LightSlateGray"), 0xFF778899);
    _mapColor.emplace(std::wstring(L"LightSteelBlue"), 0xFFB0C4DE);
    _mapColor.emplace(std::wstring(L"LightYellow"), 0xFFFFFFE0);
    _mapColor.emplace(std::wstring(L"Lime"), 0xFF00FF00);
    _mapColor.emplace(std::wstring(L"LimeGreen"), 0xFF32CD32);
    _mapColor.emplace(std::wstring(L"Linen"), 0xFFFAF0E6);
    _mapColor.emplace(std::wstring(L"Magenta"), 0xFFFF00FF);
    _mapColor.emplace(std::wstring(L"Maroon"), 0xFF800000);
    _mapColor.emplace(std::wstring(L"MediumAquamarine"), 0xFF66CDAA);
    _mapColor.emplace(std::wstring(L"MediumBlue"), 0xFF0000CD);
    _mapColor.emplace(std::wstring(L"MediumOrchid"), 0xFFBA55D3);
    _mapColor.emplace(std::wstring(L"MediumPurple"), 0xFF9370DB);
    _mapColor.emplace(std::wstring(L"MediumSeaGreen"), 0xFF3CB371);
    _mapColor.emplace(std::wstring(L"MediumSlateBlue"), 0xFF7B68EE);
    _mapColor.emplace(std::wstring(L"MediumSpringGreen"), 0xFF00FA9A);
    _mapColor.emplace(std::wstring(L"MediumTurquoise"), 0xFF48D1CC);
    _mapColor.emplace(std::wstring(L"MediumVioletRed"), 0xFFC71585);
    _mapColor.emplace(std::wstring(L"MidnightBlue"), 0xFF191970);
    _mapColor.emplace(std::wstring(L"MintCream"), 0xFFF5FFFA);
    _mapColor.emplace(std::wstring(L"MistyRose"), 0xFFFFE4E1);
    _mapColor.emplace(std::wstring(L"Moccasin"), 0xFFFFE4B5);
    _mapColor.emplace(std::wstring(L"NavajoWhite"), 0xFFFFDEAD);
    _mapColor.emplace(std::wstring(L"Navy"), 0xFF000080);
    _mapColor.emplace(std::wstring(L"OldLace"), 0xFFFDF5E6);
    _mapColor.emplace(std::wstring(L"Olive"), 0xFF808000);
    _mapColor.emplace(std::wstring(L"OliveDrab"), 0xFF6B8E23);
    _mapColor.emplace(std::wstring(L"Orange"), 0xFFFFA500);
    _mapColor.emplace(std::wstring(L"OrangeRed"), 0xFFFF4500);
    _mapColor.emplace(std::wstring(L"Orchid"), 0xFFDA70D6);
    _mapColor.emplace(std::wstring(L"PaleGoldenrod"), 0xFFEEE8AA);
    _mapColor.emplace(std::wstring(L"PaleGreen"), 0xFF98FB98);
    _mapColor.emplace(std::wstring(L"PaleTurquoise"), 0xFFAFEEEE);
    _mapColor.emplace(std::wstring(L"PaleVioletRed"), 0xFFDB7093);
    _mapColor.emplace(std::wstring(L"PapayaWhip"), 0xFFFFEFD5);
    _mapColor.emplace(std::wstring(L"PeachPuff"), 0xFFFFDAB9);
    _mapColor.emplace(std::wstring(L"Peru"), 0xFFCD853F);
    _mapColor.emplace(std::wstring(L"Pink"), 0xFFFFC0CB);
    _mapColor.emplace(std::wstring(L"Plum"), 0xFFDDA0DD);
    _mapColor.emplace(std::wstring(L"PowderBlue"), 0xFFB0E0E6);
    _mapColor.emplace(std::wstring(L"Purple"), 0xFF800080);
    _mapColor.emplace(std::wstring(L"Red"), 0xFFFF0000);
    _mapColor.emplace(std::wstring(L"RosyBrown"), 0xFFBC8F8F);
    _mapColor.emplace(std::wstring(L"RoyalBlue"), 0xFF4169E1);
    _mapColor.emplace(std::wstring(L"SaddleBrown"), 0xFF8B4513);
    _mapColor.emplace(std::wstring(L"Salmon"), 0xFFFA8072);
    _mapColor.emplace(std::wstring(L"SandyBrown"), 0xFFF4A460);
    _mapColor.emplace(std::wstring(L"SeaGreen"), 0xFF2E8B57);
    _mapColor.emplace(std::wstring(L"SeaShell"), 0xFFFFF5EE);
    _mapColor.emplace(std::wstring(L"Sienna"), 0xFFA0522D);
    _mapColor.emplace(std::wstring(L"Silver"), 0xFFC0C0C0);
    _mapColor.emplace(std::wstring(L"SkyBlue"), 0xFF87CEEB);
    _mapColor.emplace(std::wstring(L"SlateBlue"), 0xFF6A5ACD);
    _mapColor.emplace(std::wstring(L"SlateGray"), 0xFF708090);
    _mapColor.emplace(std::wstring(L"Snow"), 0xFFFFFAFA);
    _mapColor.emplace(std::wstring(L"SpringGreen"), 0xFF00FF7F);
    _mapColor.emplace(std::wstring(L"SteelBlue"), 0xFF4682B4);
    _mapColor.emplace(std::wstring(L"Tan"), 0xFFD2B48C);
    _mapColor.emplace(std::wstring(L"Teal"), 0xFF008080);
    _mapColor.emplace(std::wstring(L"Thistle"), 0xFFD8BFD8);
    _mapColor.emplace(std::wstring(L"Tomato"), 0xFFFF6347);
    _mapColor.emplace(std::wstring(L"Turquoise"), 0xFF40E0D0);
    _mapColor.emplace(std::wstring(L"Violet"), 0xFFEE82EE);
    _mapColor.emplace(std::wstring(L"Wheat"), 0xFFF5DEB3);
    _mapColor.emplace(std::wstring(L"White"), 0xFFFFFFFF);
    _mapColor.emplace(std::wstring(L"WhiteSmoke"), 0xFFF5F5F5);
    _mapColor.emplace(std::wstring(L"Yellow"), 0xFFFFFF00);
    _mapColor.emplace(std::wstring(L"YellowGreen"), 0xFF9ACD32);
}

static ColorManager colorManager;

uint32_t Color::ToRgb()
{
    uint8_t r = (uint8_t)(_color >> 16);
    uint8_t g = (uint8_t)(_color >> 8);
    uint8_t b = (uint8_t)(_color & 0xFF);

    uint32_t val = uint32_t((uint8_t)r);

    val |= (uint32_t)(((uint32_t)(g)) << 8);
    val |= (uint32_t)(((uint32_t)(b)) << 16);

    return val;
}

uint32_t Color::ToArgb()
{
    return _color;
}

uint32_t Color::ToRgb(Color clr)
{
    //#define ALPHACOLOR(d,o,alpha) ((uint8_t)(((uint32_t)(d * (255.0 - alpha) + o * alpha)) >> 8))
    return clr.ToRgb();
}

String Color::ToHex(Color clr)
{
    String strHex;
    if (Color::A(clr) == 255)
    {
        strHex.Format(L"#%02X%02X%02X", Color::R(clr), Color::G(clr), Color::B(clr));
    }
    else
    {
        strHex.Format(L"#%02X%02X%02X%02X", Color::A(clr), Color::R(clr), Color::G(clr), Color::B(clr));
    }
    return strHex;
}

String Color::ToString(Color clr)
{
    String strClr;
    strClr = colorManager.ColorToString(clr);
    return strClr;
}

Color Color::Parse(const String& strClr)
{
    uint32_t clr = 0xFF000000;
    if (strClr.IndexOf(L"#") == -1)
    {
        colorManager.GetColor(strClr, clr);
    }
    else if (strClr.Length() > 1)
    {
        if (strClr.Length() == 2)
        {
            if (strClr.Equals(L"#0"))
            {
                return ARGB(255,0,0,0);
            }
            else if (strClr.CompareI(L"#f") == 0)
            {
                return ARGB(255,255,255,255);
            }
        }

        std::wstring str(strClr.c_str() + 1);
        uint32_t uClr = std::stoul(str, 0, 16);
        if (strClr.Length() < 8)
        {
            uClr |= 0xFF000000;
        }
        clr = uClr;
    }
    return clr;
}

uint8_t Color::A(Color clr)
{
    return (uint8_t((clr._color) >> 24));
}

uint8_t Color::R(Color clr)
{
    return (uint8_t((clr._color) >> 16));
}

uint8_t Color::G(Color clr)
{
    return (uint8_t((clr._color) >> 8));
}

uint8_t Color::B(Color clr)
{
    return (uint8_t((clr._color) & 0xFF));
}

uint32_t Color::ToArgb(Color clr)
{
    return clr._color;
}

Color Color::FromRgb(uint32_t val)
{
    uint8_t b = (uint8_t)(val >> 16);
    uint8_t g = (uint8_t)(val >> 8);
    uint8_t r = (uint8_t)(val & 0xFF);

    return Color::FromRgb(r, g, b);
}

Color Color::FromRgb(uint8_t r, uint8_t g, uint8_t b)
{
    uint32_t val = uint32_t((uint8_t)b);

    val |= (uint32_t)(((uint32_t)(g)) << 8);
    val |= (uint32_t)(((uint32_t)(r)) << 16);

    return Color(val | 0xFF000000);
}

Color Color::FromArgb(uint8_t a, uint8_t r, uint8_t g, uint8_t b)
{
    uint32_t val = uint32_t((uint8_t)b);

    val |= (uint32_t)(((uint32_t)(g)) << 8);
    val |= (uint32_t)(((uint32_t)(r)) << 16);
    val |= (uint32_t)(((uint32_t)(a)) << 24);

    return Color(val);
}

}
